home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / modelers / chmsthtc / chmsthtc.lzh / Chemesthetics / Source / Source.LZH / diskio.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-22  |  5.2 KB  |  211 lines

  1. /* $Revision Header *** Header built automatically - do not edit! ***********
  2.  *
  3.  *    (C) Copyright 1991 by Metalworx
  4.  *
  5.  *    Name .....: diskio.c
  6.  *    Created ..: Wed 02-Oct-91 12:15
  7.  *    Revision .: 1
  8.  *
  9.  *    Date        Author        Comment
  10.  *    =========    ========    ====================
  11.  *    20-Oct-91    Mtwx        Icon fⁿr .CDM-Datei
  12.  *    02-Oct-91    Mtwx        Created this file!
  13.  *
  14.  * $Revision Header ********************************************************/
  15.  #define REVISION 1
  16.  
  17. /***************************************************************************
  18. * diskio.c: Laden und Speichern eines Molekⁿl-Datenfiles           *
  19. ***************************************************************************/
  20.  
  21. /* ------------------------------- includes ----------------------------- */
  22.  
  23. #include <math.h>
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <exec/libraries.h>
  27. #include <intuition/intuition.h>
  28. #include <libraries/reqbase.h>
  29. #include <workbench/workbench.h>
  30. #include <clib/req_protos.h>
  31. #include <req.h>
  32. #include <proto/dos.h>
  33. #include <proto/exec.h>
  34. #include <proto/icon.h>
  35. #include <proto/arp.h>
  36.  
  37. #include <mtwx_defs.h>
  38.  
  39. #include "chem_defs.h"
  40. #include "messages.h"
  41. #include "cdmicon.h"
  42.  
  43. /* ------------------------------- external references ------------------ */
  44.  
  45. extern BOOL reqlib_used;
  46. extern int atomanz,ref,drehx,drehy,drehz,HEIGHT;
  47. extern char dn[],Titel[],Dateiname[],IFFDateiname[];
  48. extern ATOMTYP     *a[],*alt[];    /* Atome */
  49. extern double zf;
  50. extern VEKTOR l;            /* Lichtquelle */
  51. extern struct Window *Window1;
  52. extern struct Screen *FirstScreen;
  53. extern struct ReqLib *ReqBase;
  54. extern struct ReqFileRequester *FileStr;
  55.  
  56. /* ------------------------------- prototypes --------------------------- */
  57.  
  58. extern void Werte_loeschen(void);
  59. extern void SimpleRequest(char *,...);
  60.  
  61. /* ------------------------------- routines ----------------------------- */
  62.  
  63. int      dateieinlesen()
  64.  /* versucht, die Molekuel-Datei dn einzulesen */
  65. {
  66.   char        dummy[20];
  67.   int        i;
  68.   FILE       *datei;
  69.  
  70.   strcpy(Titel,LOAD_MOL);
  71.   if(FileRequester(FileStr))
  72.   {
  73.     datei = fopen(dn, "r");
  74.     if (datei)
  75.     {
  76.       Waitpointer_On(Window1,DISKWAIT);
  77.       Werte_loeschen();                /* alte Werte loeschen */
  78.       fgets(dummy,4,datei);
  79.       atomanz=atoi(dummy);
  80.       if(atomanz==0)
  81.       {
  82.     Waitpointer_Off(Window1);
  83.     SimpleRequest(WRONG_DATA);
  84.     return 0;
  85.       }
  86.       if(atomanz>499)
  87.       {
  88.     Waitpointer_Off(Window1);
  89.     SimpleRequest(TOO_MUCH_DATA);
  90.     return 0;
  91.       }
  92.       for (i = 1; i <= atomanz; i++)
  93.       {
  94.     a[i]=ArpAlloc(sizeof(ATOMTYP));
  95.     alt[i]=ArpAlloc(sizeof(ATOMTYP));
  96.     if(a[i]==NULL || alt[i]==NULL)
  97.       /* alert!! */
  98.       return 0;
  99.     fgets(a[i]->name, 4, datei);
  100.     a[i]->name[strlen(a[i]->name)-1]='\0';  /* \n loeschen */
  101.     fgets(dummy,7,datei); a[i]->x=atoi(dummy);
  102.     fgets(dummy,7,datei); a[i]->y=atoi(dummy);
  103.     fgets(dummy,7,datei); a[i]->z=atoi(dummy);
  104.     fgets(dummy,7,datei); a[i]->r=atoi(dummy);
  105.     *alt[i] = *a[i];          /* Originale f. Editieren sichern */
  106.       }
  107.       fgets(dummy,19,datei); zf=atof(dummy);
  108.       fgets(dummy,19,datei); drehx=atoi(dummy);
  109.       fgets(dummy,19,datei); drehy=atoi(dummy);
  110.       fgets(dummy,19,datei); drehz=atoi(dummy);
  111.       fgets(dummy,19,datei); l.x=atof(dummy);
  112.       fgets(dummy,19,datei); l.y=atof(dummy);
  113.       fgets(dummy,19,datei); l.z=atof(dummy);
  114.       fgets(dummy,19,datei); ref=atoi(dummy);
  115.       fclose(datei);
  116.       Waitpointer_Off(Window1);
  117.       if (zf == 0.0 || zf > 100)
  118.       {
  119.     SimpleRequest(WRONG_DATA);
  120.     return 0;
  121.       }
  122.       else
  123.     return 1;
  124.     }
  125.     else
  126.       return 0;
  127.   }
  128.   else
  129.     return 0;
  130.   reqlib_used=TRUE; /* wirklich benutzt! */
  131. }
  132.  
  133. void      dateispeichern(BOOL CDMIcon)             /* speichert die Molekuel-Datei */
  134. {
  135.   int        i;
  136.   FILE *datei;
  137.   struct Library *IconBase;
  138.  
  139.   strcpy(Titel,SAVE_MOL);
  140.   if(FileRequester(FileStr))
  141.   {
  142.     datei = fopen(dn, "w");
  143.     if (datei)
  144.     {
  145.       Waitpointer_On(Window1,DISKWAIT);
  146.       fprintf(datei, "%d\n", atomanz);
  147.       for (i = 1; i <= atomanz; i++)
  148.       {
  149.     fprintf(datei, "%s\n", alt[i]->name);
  150.     fprintf(datei, "%d\n", alt[i]->x);
  151.     fprintf(datei, "%d\n", alt[i]->y);
  152.     fprintf(datei, "%d\n", alt[i]->z);
  153.     fprintf(datei, "%d\n", alt[i]->r);
  154.       }
  155.       fprintf(datei, "%lf\n", zf);
  156.       fprintf(datei, "%d\n", drehx);
  157.       fprintf(datei, "%d\n", drehy);
  158.       fprintf(datei, "%d\n", drehz);
  159.       fprintf(datei, "%lf\n", l.x);
  160.       fprintf(datei, "%lf\n", l.y);
  161.       fprintf(datei, "%lf\n", l.z);
  162.       fprintf(datei, "%d\n", ref);
  163.       fclose(datei);
  164.       Waitpointer_Off(Window1);
  165.       if(CDMIcon==TRUE)
  166.       {
  167.     IconBase = OpenLibrary("icon.library", 0);
  168.     if (IconBase != NULL)
  169.     {
  170.       if (!PutDiskObject(dn, &cdmiconIcon))
  171.       {
  172.         DisplayBeep(0L);
  173.         SimpleRequest(ERROR_PUT_ICON);
  174.       }
  175.       CloseLibrary(IconBase);
  176.     }
  177.     else
  178.       SimpleRequest(NO_ICON_LIB);
  179.       }
  180.     }
  181.   }
  182.   reqlib_used=TRUE; /* wirklich benutzt! */
  183. }
  184.  
  185. void      Bild_speichern()
  186. {
  187.   int        i;
  188.  
  189.   i = strpos(Dateiname, ".cdm");
  190.   if (i > 0)
  191.   {
  192.     strncpy(IFFDateiname, Dateiname, i);
  193.     IFFDateiname[i] = '\0';
  194.     strcat(IFFDateiname, ".iff");
  195.   }
  196.   strcpy(Titel,SAVE_IFF);
  197.   strcpy(Dateiname,IFFDateiname);
  198.   if(FileRequester(FileStr))
  199.   {
  200.     Waitpointer_On(Window1,DISKWAIT);
  201.     if(!(save(dn,FirstScreen,Window1->Width,HEIGHT)))
  202.     {
  203.       Waitpointer_Off(Window1);
  204.       SimpleRequest("%s", IFF_ERROR);
  205.     }
  206.     Waitpointer_Off(Window1);
  207.   }
  208.   reqlib_used=TRUE;
  209. }
  210.  
  211.